{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "from utils import read_arff\n",
    "from apriori import apriori\n",
    "from fpgrowth import fpgrowth"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>outlook</th>\n",
       "      <th>temperature</th>\n",
       "      <th>humidity</th>\n",
       "      <th>windy</th>\n",
       "      <th>play</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>sunny</td>\n",
       "      <td>hot</td>\n",
       "      <td>high</td>\n",
       "      <td>False</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>sunny</td>\n",
       "      <td>hot</td>\n",
       "      <td>high</td>\n",
       "      <td>True</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>overcast</td>\n",
       "      <td>hot</td>\n",
       "      <td>high</td>\n",
       "      <td>False</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>rainy</td>\n",
       "      <td>mild</td>\n",
       "      <td>high</td>\n",
       "      <td>False</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>rainy</td>\n",
       "      <td>cool</td>\n",
       "      <td>normal</td>\n",
       "      <td>False</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    outlook temperature humidity  windy play\n",
       "0     sunny         hot     high  False   no\n",
       "1     sunny         hot     high   True   no\n",
       "2  overcast         hot     high  False  yes\n",
       "3     rainy        mild     high  False  yes\n",
       "4     rainy        cool   normal  False  yes"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nominal = read_arff('./dataset/weather.nominal.arff')\n",
    "nominal.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'overcast', 'rainy', 'sunny'}"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "set(nominal['outlook'].tolist())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'high', 'normal'}"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "set(nominal['humidity'].tolist())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>outlook</th>\n",
       "      <th>temperature</th>\n",
       "      <th>humidity</th>\n",
       "      <th>windy</th>\n",
       "      <th>play</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>sunny</td>\n",
       "      <td>hot</td>\n",
       "      <td>high</td>\n",
       "      <td>False</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>sunny</td>\n",
       "      <td>hot</td>\n",
       "      <td>high</td>\n",
       "      <td>True</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>rainy</td>\n",
       "      <td>cool</td>\n",
       "      <td>normal</td>\n",
       "      <td>True</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>sunny</td>\n",
       "      <td>mild</td>\n",
       "      <td>high</td>\n",
       "      <td>False</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>rainy</td>\n",
       "      <td>mild</td>\n",
       "      <td>high</td>\n",
       "      <td>True</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   outlook temperature humidity  windy play\n",
       "0    sunny         hot     high  False   no\n",
       "1    sunny         hot     high   True   no\n",
       "5    rainy        cool   normal   True   no\n",
       "7    sunny        mild     high  False   no\n",
       "13   rainy        mild     high   True   no"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nominal[nominal['play'] == 'no']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1: {frozenset({'normal'}), frozenset({'yes'}), frozenset({False})}, 2: {frozenset({False, 'yes'}), frozenset({'normal', 'yes'})}}\n",
      "[[{'yes'}, {False}, 0.6666666666666666], [{'yes'}, {'normal'}, 0.6666666666666666], [{False}, {'yes'}, 1.0], [{'normal'}, {'yes'}, 1.0]]\n"
     ]
    }
   ],
   "source": [
    "freq_item_set, rules = apriori([nominal[nominal['play'] == 'yes'].loc[i].to_list() for i in nominal[nominal['play'] == 'yes'].index.tolist()], 0.5, 0.5)\n",
    "print(freq_item_set)\n",
    "print(rules)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{False}, {False, 'yes'}, {'normal'}, {'normal', 'yes'}, {'yes'}]\n",
      "[[{False}, {'yes'}, 1.0], [{'yes'}, {False}, 0.6666666666666666], [{'normal'}, {'yes'}, 1.0], [{'yes'}, {'normal'}, 0.6666666666666666]]\n"
     ]
    }
   ],
   "source": [
    "freq_item_set, rules = fpgrowth([nominal[nominal['play'] == 'yes'].loc[i].to_list() for i in nominal[nominal['play'] == 'yes'].index.tolist()], 0.5, 0.5)\n",
    "print(freq_item_set)\n",
    "print(rules)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1: {frozenset({'no'}), frozenset({'high'}), frozenset({True}), frozenset({'sunny'})}, 2: {frozenset({True, 'no'}), frozenset({'high', 'sunny'}), frozenset({'no', 'sunny'}), frozenset({'high', 'no'})}, 3: {frozenset({'high', 'no', 'sunny'})}}\n",
      "[[{'no'}, {True}, 0.6], [{'no'}, {'sunny'}, 0.6], [{'no'}, {'high', 'sunny'}, 0.6], [{'high'}, {'sunny'}, 0.75], [{'high'}, {'no', 'sunny'}, 0.75], [{'high', 'no'}, {'sunny'}, 0.75], [{'no'}, {'high'}, 0.8], [{True}, {'no'}, 1.0], [{'sunny'}, {'high'}, 1.0], [{'sunny'}, {'no'}, 1.0], [{'high'}, {'no'}, 1.0], [{'sunny'}, {'high', 'no'}, 1.0], [{'high', 'sunny'}, {'no'}, 1.0], [{'no', 'sunny'}, {'high'}, 1.0]]\n"
     ]
    }
   ],
   "source": [
    "freq_item_set, rules = apriori([nominal[nominal['play'] == 'no'].loc[i].to_list() for i in nominal[nominal['play'] == 'no'].index.tolist()], 0.5, 0.5)\n",
    "print(freq_item_set)\n",
    "print(rules)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1: {frozenset({'no'}), frozenset({'high'}), frozenset({True}), frozenset({'sunny'})}, 2: {frozenset({True, 'no'}), frozenset({'high', 'sunny'}), frozenset({'no', 'sunny'}), frozenset({'high', 'no'})}, 3: {frozenset({'high', 'no', 'sunny'})}}\n",
      "[[{'no'}, {True}, 0.6], [{'no'}, {'sunny'}, 0.6], [{'no'}, {'high', 'sunny'}, 0.6], [{'high'}, {'sunny'}, 0.75], [{'high'}, {'no', 'sunny'}, 0.75], [{'high', 'no'}, {'sunny'}, 0.75], [{'no'}, {'high'}, 0.8], [{True}, {'no'}, 1.0], [{'sunny'}, {'high'}, 1.0], [{'sunny'}, {'no'}, 1.0], [{'high'}, {'no'}, 1.0], [{'sunny'}, {'high', 'no'}, 1.0], [{'high', 'sunny'}, {'no'}, 1.0], [{'no', 'sunny'}, {'high'}, 1.0]]\n"
     ]
    }
   ],
   "source": [
    "freq_item_set, rules = apriori([nominal[nominal['play'] == 'no'].loc[i].to_list() for i in nominal[nominal['play'] == 'no'].index.tolist()], 0.5, 0.5)\n",
    "print(freq_item_set)\n",
    "print(rules)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.6 ('env': venv)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "e6a44bc4ae6224bc4bc7b3a89841677b0124c79fe22f3d101cb1ffa8756f30f3"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
